package cn.pconline.autoclub.entity;

import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

import com.alibaba.fastjson.JSONObject;

@Entity(tableName = "ac_club_album_photo", split = "Mod:albumId:10")
public class Photo {

    public final static int STATUS_NORMAL = 1;  // 正常状态
    public final static int STATUS_DELETE = -1; // 已删除状态
    @Id
    @Column(name = "photo_id")
    private long photoId; // ID
    @Column(name = "album_id")
    private long albumId; // 相册ID
    @Column(name = "name")
    private String name; // 名称
    @Column(name = "url")
    private String url; // url
    @Column(name = "create_by")
    private long createBy; // 创建者
    @Column(name = "create_at")
    private Date createAt; // 创建时间
    @Column(name = "update_at")
    private Date updateAt; // 更新时间
    @Column(name = "status")
    private int status = STATUS_NORMAL; // 状态
    private int width;
    private int height;
    @Column(name = "post_count")
    private long postCount; // 评论数
    @Column(name = "praise_count")
    private long praiseCount; // 赞数
    
    @Transient
    public String url160x120;
    @Transient
    public String url700x;
    @Transient
    public String url144x144;
    @Transient
    public String url160x107;

    public long getPostCount() {
		return postCount;
	}

	public void setPostCount(long postCount) {
		this.postCount = postCount;
	}

	public long getPraiseCount() {
		return praiseCount;
	}

	public void setPraiseCount(long praiseCount) {
		this.praiseCount = praiseCount;
	}

	public String getUrl144x144() {
        return converImg("_144x144");
    }
	
	// 160x120图片url拼接
    public String getUrl160x120() {
        return converImg("_160x120");
    }
    
    public String getUrl240x160() {
        return converImg("_240x160");
    }
    // 160x107图片url拼接

    public String getUrl160x107() {
        return converImg("_160x107");
    }

    public String getUrl330x220() {
        return converImg("_330x220");
    }
    // 700等比图片url拼接

    public String getUrl700x() {
        return converImg("_700");
    }
    // 700等比图片url拼接

    public String getUrl400x() {
        return converImg("_400x400");
    }
    
    public String getUrl120x80(){
    	return converImg("_120x80");
    }
    
    public String getUrl106x107(){
    	return converImg("_106x107");
    }

    private String converImg(String size) {
        if (StringUtils.isBlank(url)) {
            return url;
        }
        if (url.indexOf("_1024x1024") != -1) {
            return url.replaceAll("_1024x1024", size);
        } else {
            int dot = url.lastIndexOf(".");
            return url.substring(0, dot) + size + url.substring(dot, url.length());
        }
    }

    public long getPhotoId() {
        return photoId;
    }

    public void setPhotoId(long photoId) {
        this.photoId = photoId;
    }

    public long getAlbumId() {
        return albumId;
    }

    public void setAlbumId(long albumId) {
        this.albumId = albumId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    @Override
    public int hashCode() {
        return String.valueOf(this.photoId).hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Photo)) {
            return false;
        }
        Photo photo = (Photo) obj;
        if (photo.getPhotoId() == this.photoId) {
            return true;
        }
        return false;
    }
    
    public JSONObject toJson(){
    	JSONObject jsonObject = new JSONObject();
    	jsonObject.put("albumId", getAlbumId());
    	jsonObject.put("photoId", getPhotoId());
    	jsonObject.put("createAt", getCreateAt());
    	jsonObject.put("createBy", getCreateBy());
    	return jsonObject;
    }
    
    
}
